﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XH.SmartParking.IService;
using XH.SmartParking.Entities;

namespace XH.SmartParking.Service
{
    public class RoleService : BaseService, IRoleService
    {
        public RoleService(DbContext context)
            : base(context)
        {

        }

        public bool CheckRoleName(string roleName, int roleId)
        {
            return Query<SysRole>(r =>
                                        r.RoleName == roleName &&
                                        r.RoleId != roleId)
                .Count() > 0;
        }

        public IEnumerable<SysRole> GetRoles(string key)
        {
            return Set<SysRole>()
                  .Include(r => r.Users)
                  .Include(r => r.Menus)
                  .Where(r =>
                      string.IsNullOrEmpty(key) ||
                      r.RoleName.Contains(key) ||
                      r.RoleDesc.Contains(key)
                  );
            //return this.Query<SysRole>(m =>

            //    string.IsNullOrEmpty(key) ||

            //    m.RoleName.Contains(key) ||

            //    m.RoleDesc.Contains(key)
            //);
        }
    }
}
